package pomodorotasks

import griffon.core.GriffonApplication
import griffon.test.GriffonUnitTestCase

import com.google.api.services.tasks.model.TaskLists
import com.google.api.services.tasks.model.TaskList

import pomodorotasks.testutils.ThreadingUtils
import pomodorotasks.testutils.PomodoroApplicationFacade
import pomodorotasks.testutils.GoogleTasksUtils

class PomodoroTasksTests extends GriffonUnitTestCase {
    GriffonApplication app
    
    PomodoroApplicationFacade pomodoroApp
    
    def googleAppService
    def view
    def controller
    def model

    protected void setUp() {
        super.setUp()
        pomodoroApp = new PomodoroApplicationFacade(app, this)
        googleAppService = pomodoroApp.mockGoogleTasksService()
        pomodoroApp.startApp()
        
        controller = app.controllers['PomodoroTasks']
        view = app.views['PomodoroTasks']
        model = app.models['PomodoroTasks']
    }

    protected void tearDown() {
        super.tearDown()
    }
    
    private void assertListsComboBoxContains(taskListNames) {
        int size = taskListNames.size()
        assertEquals(size, model.lists.size())
        assertEquals(size, view.listsComboBox.itemCount)
        taskListNames.eachWithIndex { name, index ->
            assertEquals(name, view.listsComboBox.getItemAt(index))
        }
    }
    
    void testTasksListComboIsFilledWithOneElements() {
        def taskListsNames = ['TaskList 1']
        pomodoroApp.addTaskLists(taskListsNames)
        execSync {
            assertListsComboBoxContains(taskListsNames)
        }
    }

    void testTasksListComboIsFilledWithTwoElements() {
        def taskListsNames = ['TaskList 1', 'TaskList 2']
        pomodoroApp.addTaskLists(taskListsNames)
        execSync {
            assertListsComboBoxContains(taskListsNames)
        }
    }
}
